package cn.com.netedge.iot.frontend.datasave.model.freeze;

import java.util.ArrayList;
import java.util.List;

public class SpecialEventDataModel {

    private int deviceId;
    private String taskObis;
    /*数据库表名*/
    private String tableName;
    /*动态列值以及类型*/
    private List<ColumnDataModel> columnDataModels;

    public String getDynamicsValues() {
        if (!columnDataModels.isEmpty()) {
            StringBuilder valueStr = new StringBuilder();
            for (ColumnDataModel col : columnDataModels
            ) {
                if ("numeric".equals(col.getDataType())) {
                    valueStr.append(",").append(col.getDataValue().contains(",") ? col.getDataValue().replace(',', '.') : col.getDataValue());
                } else {

                    valueStr.append(",'").append(col.getDataValue()).append("'");
                }
            }
            return valueStr.toString();
        }
        return "";
    }

    public String getDynamicsColumns() {
        if (!columnDataModels.isEmpty()) {
            StringBuilder colStr = new StringBuilder();
            for (ColumnDataModel col : columnDataModels
            ) {
                colStr.append(",").append(col.getColumnName());
            }
            return colStr.toString();
        }
        return "";
    }

    public int getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(int deviceId) {
        this.deviceId = deviceId;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public List<ColumnDataModel> getColumnDataModels() {
        return columnDataModels;
    }

    public void setColumnDataModels(List<ColumnDataModel> columnDataModels) {
        this.columnDataModels = columnDataModels;
    }

    public SpecialEventDataModel() {
        this.columnDataModels = new ArrayList<>();
    }

    public String getTaskObis() {
        return taskObis;
    }

    public void setTaskObis(String taskObis) {
        this.taskObis = taskObis;
    }
}
